<template>
	<view class="newsBottom">
		<view class="content">
			<view class="msg">
				<view class="left">
					<!-- 	<u-image  width="66" height="66" class="img" src="http://www.people.com.cn/img/2016people/images/rmw_logo.png"
					 shape="circle"> -->

					</u-image>
					<view class="inform">
						<view class="top">
							<text class="source">{{item.source || "暂无"}}</text>
							<view class="tag" v-if="item.columnList && item.columnList.length>0">
								{{item.columnList[0].columnName}}
							</view>
						<!-- 	<view class="tag more" v-if="item.columnList && item.columnList.length>1">
								...
							</view> -->
						</view>
						<view class="bottom">
							<text class="time" v-if="item.showDate">{{handleDate(item.showDate, 'yyyy-MM-dd')}}</text>
							<!-- 		<text class="iconfont iconchakanliang"></text> -->
							<u-icon name="eye" size="30"></u-icon>
							<text class="count">{{handleCount(item.lookNum || 0,10000)}}</text>
						</view>
						<!-- 	<text class="txt">人民网</text>
						<view class="matter">
							<view class="time">
								2020-09-07
							</view>
							<view class="tag">
								理论宣讲
							</view>
								  <view class="tag more">
							  </view>
							<text class="iconfont iconchakanliang"></text>
							<text class="see_count">6565</text>
						</view> -->
					</view>
				</view>
				<view class="right">
					<check-user-status @click="handleZan">
						<view class="item good">
							<!-- <u-badge v-if="!isZan" :is-center="true" type="error" count="7777" :offset="[10,45]" bgColor="rgba(0,0,0,0)">
							</u-badge>
							<u-badge v-else overflow-count="99"  type="error" count="7777"  bgColor="rgba(0,0,0,0)" color="#EB4D3C">
						
							</u-badge> -->
							<text v-if="!item.isGood" class="iconfont icondianzan2"></text>
							<text v-else class="iconfont iconyidianzan"></text>
							<text class="count" :class="{isZan:item.isGood == 1}">{{handleCount(item.goodNum || 0,10000)}}</text>
						</view>
					</check-user-status>
					<check-user-status @click="handleCollect">
						<view class="item">
							<text v-if="!item.isCollect" class="iconfont iconshoucang"></text>
							<text v-else class="iconfont iconyishoucang"></text>
							<!-- 	<text class="count">3021</text> -->
						</view>
					</check-user-status>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import CheckUserStatus from "@/components/CheckUserStatus.vue"
	import {
		handleDate,
		handleCount
	} from '@/utils/util.js'

	export default {
		props: {
			item: {
				type: Object,
				default: () => {}
			},
		},
		components: {
			CheckUserStatus
		},
		data() {
			return {
				isLike: true,
				isZan: true
			};
		},
		methods: {
			handleDate,
			handleCount,
			async handleZan() {
				if (!this.item.isGood) {
					await this.doZan();
					return;
				}
				await this.cancleZan();
			},
			async handleCollect() {
				if (!this.item.isCollect) {
					await this.doCollect();
					return;
				}
				await this.cancelCollect();
			},
			async doZan() {

				const result = await this.$api.insertGood({
					pCode: this.item.newsCode,
					goodType:7,
					goodUserCode: this.store_user_code,
				});

				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '点赞成功',
						type: 'success',
						duration: 2000
					});
					this.item.goodNum = this.item.goodNum + 1;
					this.item.isGood = 1;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "点赞失败",
					type: 'error',
					duration: 2000
				});
			},
			async cancleZan() {
				const result = await this.$api.deleteGood({
				pCode: this.item.newsCode,
				goodType:7,
				goodUserCode: this.store_user_code
				});
				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '已取消点赞',
						type: 'success',
						duration: 2000
					});
					this.item.goodNum = this.item.goodNum - 1;
					this.item.isGood = 0;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "取消失败",
					type: 'error',
					duration: 2000
				});
			},
			async doCollect() {
				const result = await this.$api.addNewsCollection({
					newsCode: this.item.newsCode,
					newsName: this.item.newsName,
					userCode: this.store_user_code
				});

				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '收藏成功',
						type: 'success',
						duration: 2000
					});
					this.item.isCollect = 1;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "收藏失败",
					type: 'error',
					duration: 2000
				});
			},
			async cancelCollect() {
				const result = await this.$api.deleteNewsCollection({
					newsCode: this.item.newsCode,
					userCode: this.store_user_code
				});
				if (result.resultCode === '200') {
					this.$refs.uToast.show({
						title: result.resultMsg || '已取消收藏',
						type: 'success',
						duration: 2000
					});
					this.item.isCollect = 0;
					return;
				}
				this.$refs.uToast.show({
					title: result.resultMsg || "取消收藏失败",
					type: 'error',
					duration: 2000
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "../../../../../commom/styles/icons.css";

	.newsBottom {
		width: 100%;
		position: fixed;
		bottom: 0;
		background: tranp;

		.content {
			width: 100%;
			padding-left: 22rpx;
			padding-right: 22rpx;
			height: 100rpx;
			padding-bottom: 0;
			// padding-top: 5rpx;
			background: #333333;
			display: flex;
			// align-items: center;
             flex-direction: column;
			 
			.msg {
				width: 100%;
				height: 100%;
				// padding-top: 26rpx;
				// padding-bottom: 8rpx;
				display: flex;
				align-items: center;
                
				.left {
					flex: 1;
					display: flex;
                    height: 100%;
					
					.img {
						// border: 1px solid #D8D8D8;
						width: 66rpx;
						height: 66rpx;
					}

					.inform {
						height: 100%;
						display: flex;
						flex-direction: column;
						
						justify-content: space-between;
						

						.top {
							display: flex;
                             margin-top: 12rpx;
							.source {
								flex: 1;
								font-size: 30rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #FFFFFF;
								margin-right: 42rpx;
								max-width: 400rpx;
								@include line-ellipsis(1);
							}

							.tag {
								padding: 3rpx 16rpx;
								border-radius: 5rpx;
								background: #FF7D77;
								color: #FFFFFF;
								font-size: 20rpx;
								display: flex;
								align-items: center;

								&.more {
									margin-left: 10rpx;
								}
							}
						}

						.bottom {
							color: #FFFFFF;
							display: flex;
							height: 33rpx;
							align-items: center;
                            margin-bottom: 12rpx;
							.time {
								font-size: 22rpx;
								font-weight: 400;
								margin-right: 30rpx;
							}

							.iconfont {
								font-size: 29rpx;

							}

							.count {
								margin-left: 11rpx;
								font-size: 24rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #FFFFFF;

							}
						}
					}
				}

				.right {
					display: flex;

					.item {
						display: flex;
						// flex-direction: column;
						// align-items: center;
						color: #9E9E9E;
						font-size: 24rpx;
						margin-top: 10rpx;
						// height: 66rpx;


						&.good {
							margin-right: 15rpx;
						}

						.isZan {
							color: #EB4D3C;
						}

						.iconfont {
							font-size: 35rpx;
							margin-bottom: 6rpx;
							line-height: 66rpx;

							&.iconyidianzan {
								background-image: linear-gradient(90deg, #FE614F 0%, #EB4D3C 100%);
								-webkit-background-clip: text;
								color: transparent;
							}

							&.iconyishoucang {
								background-image: linear-gradient(150deg, #FFED6F 1%, #FFCF01 100%);
								-webkit-background-clip: text;
								color: transparent;
							}
						}
					}
				}
			}
		}
	}
</style>
